<template>
    <Container class="brand-list">
        <Tabs v-model="tab">
            <Button
                size="large"
                class="item"
                type="primary"
                slot="extra"
                icon="md-add"
                @click="onAddType">添加类型</Button>
            <TabPane label="门店类型" name="tab1">
                <Table
                  :height="options.tableHeight"
                  stripe
                  :columns="list.columns"
                  :data="list.data"
                  no-data-text="亲，没有找到相关记录哦！~"></Table>
               
								<Loader :status="list.status" @refresh="getData"></Loader>
            </TabPane>
        </Tabs>
				<StoreEditItem ref="storeEdit" @complete="getData"></StoreEditItem>
    </Container>
</template>
<script>
import table from "@/table"
import StoreListData from "./list/StoreListData"
import StoreEditItem from "./edit/StoreEditItem"
import { clearEmpty } from '@/util'
export default {
	components: {
		StoreEditItem
	},
  data() {
    return {
      keyword: "",
      tab: "tab1",
      list: StoreListData,
      options: {
        tableHeight: 300
      },
    };
  },
  mounted() {
    this.list.currentPage =  ~~this.$route.query.currentPage || 1;
    this.list.pageSize = ~~this.$route.query.pageSize || this.list.pageSize;
		this.initTable();
		this.$bus.$on("onAddType", this.onAddType);
    this.$bus.$on("onEdit", this.onEdit);
    this.$bus.$on("onDelete", this.onDelete);
		this.getData();
  },
  destroyed() {
    this.$bus.$off();
  },
  methods: {
    ...table,
    onSearchBtnClick() {
			this.list.currentPage = 1;
			this.getData();
		},
    getData() {
      this.list.status = "loading"
      this.$ajaxGet("/storeType/findAll").then(data => {
          this.list.data = []
          this.list.totalItem = Number(data.total)
          this.list.data = (data || []).map(item => {
            return {
							name: item.name,
              id: item.id,
              isSpecial: item.isSpecial,
              isCalculateIntegral: item.isCalculateIntegral,
              isCalculateRebate: item.isCalculateRebate,
              isCalculateFund: item.isCalculateFund,
              isBarcodeStoreOut: item.isBarcodeStoreOut
            }
          })
          this.list.status = "pass"
          this.backTableTop()
        }).catch(() => {
          this.list.status = "error"
        })
		},
    onAddType() {
      this.$refs.storeEdit.updateForm();
		},
		onEdit(row) {
			this.$refs.storeEdit.updateForm(row);
		},
    onDelete(id, name, index) {
			this.$Modal.confirm({
        title: "删除",
        content: "确定删除当前门店类型？",
        onOk: () => {
          this.$ajaxPost(`/storeType/delete/${id}`).then(data => {
            this.$Notice.success({
              title: "删除成功",
              desc: `<span class="font-red">${name}</span> 已被删除。`
            });
            this.getData();
          })
        }
      });
		},
   
	},

};
</script>
